package com.bigcat.gulimall.gulimallproduct.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bigcat.gulimall.common.utils.PageUtils;
import com.bigcat.gulimall.common.utils.Query;
import com.bigcat.gulimall.gulimallproduct.dao.AttrDao;
import com.bigcat.gulimall.gulimallproduct.entity.AttrEntity;
import com.bigcat.gulimall.gulimallproduct.service.AttrService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@Service("attrService")
public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements AttrService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<AttrEntity> page = this.page(
                new Query<AttrEntity>().getPage(params),
                new QueryWrapper<AttrEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * 批量获得属性id值
     * @param attrIdList
     * @return
     */
    @Override
    public List<Long> selectSearchByAttrs(List<Long> attrIdList) {
        if (attrIdList.size()>0){
            List<AttrEntity> attrEntityList = baseMapper.selectBatchIds(attrIdList);
            if (attrEntityList==null || attrEntityList.size()==0){
                return new ArrayList<>();
            }
            return attrEntityList.stream().map(AttrEntity::getAttrId).collect(Collectors.toList());
        }
        return new ArrayList<>();


    }

}